package logic

import (
	"context"
	"gorm.io/gorm"
	"merchantmanager/models/mysql"

	"merchantmanager/merrpc/internal/svc"
	"merchantmanager/merrpc/merrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MerUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMerUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MerUpdateLogic {
	return &MerUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MerUpdateLogic) MerUpdate(in *merrpc.MerUpdateRequest) (*merrpc.MerUpdateResponse, error) {
	// todo: add your logic here and delete this line
	var merrs mysql.Merchants
	mysql.DB.Where("id =?", in.Id).Find(&merrs)
	mer := mysql.Merchants{
		Model: gorm.Model{ID: uint(in.Id)},
		Name:  in.Name,
		Price: float64(in.Price),
		Image: int(in.Image),
	}
	mysql.DB.Debug().Updates(&mer)
	return &merrpc.MerUpdateResponse{
		Id: int64(mer.ID),
	}, nil
}
